package com.hi.hiparty.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

public class IDGenerator {

	public static final String DEFUALT_DATETIME_FORMAT_STRING = "yyMMddHHmm";

	public static SimpleDateFormat dateFormat = new SimpleDateFormat(DEFUALT_DATETIME_FORMAT_STRING);

	public static String genUserId() {
		return getRandomNumberCode(8);
	}

	/**
	 * 生成制定长度的随机串,0-9数字混排
	 * 
	 * @return
	 */
	public static String getRandomNumberCode(int length) {
		String[] list = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };
		Random r = new Random();
		StringBuffer result = new StringBuffer();
		for (int i = 0; i < length; i++) {
			result.append(list[r.nextInt(9)]);
		}
		return result.toString();
	}

	public static String generatePartyid() {
		return dateFormat.format(new Date())
				+ UUID.randomUUID().toString().replaceAll("-", "").toUpperCase().substring(0, 6);
	}

	public static String generatePostid(String partyid) {
		return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase().substring(0, 6);
	}

	public static void main(String[] args) {
		for (int i = 0; i < 10; i++) {
			System.out.println(generatePartyid());
		}

	}
}
